package com.action;

import java.io.ByteArrayInputStream;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.ResultPath;

import com.util.RandomNumUtil;

/**
 * 6位验证码
 * 
 * @author Administrator
 * 
 */
@ParentPackage("json-default")
@Namespace("/action")
@ResultPath("/")
public class RandomAction extends BaseAction {
	private ByteArrayInputStream inputStream;

	@Action(value = "rand", results = { @Result(type = "stream", params = { "contentType", "image/jpeg", "inputName", "inputStream" }) })
	public String execute() throws Exception {
		RandomNumUtil rdnu = RandomNumUtil.Instance();
		this.setInputStream(rdnu.getImage());// 取得带有随机字符串的图片
		this.setSession("random", rdnu.getString());// 取得随机字符串放入HttpSession
		return SUCCESS;
	}

	public void setInputStream(ByteArrayInputStream inputStream) {
		this.inputStream = inputStream;
	}

	public ByteArrayInputStream getInputStream() {
		return inputStream;
	}
}